﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CalendarMod
{
    /// <summary>
    /// 按照步骤 1a 或 1b 操作，然后执行步骤 2 以在 XAML 文件中使用此自定义控件。
    ///
    /// 步骤 1a) 在当前项目中存在的 XAML 文件中使用该自定义控件。
    /// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根
    /// 元素中:
    ///
    ///     xmlns:MyNamespace="clr-namespace:CalendarMod"
    ///
    ///
    /// 步骤 1b) 在其他项目中存在的 XAML 文件中使用该自定义控件。
    /// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根
    /// 元素中:
    ///
    ///     xmlns:MyNamespace="clr-namespace:CalendarMod;assembly=CalendarMod"
    ///
    /// 您还需要添加一个从 XAML 文件所在的项目到此项目的项目引用，
    /// 并重新生成以避免编译错误:
    ///
    ///     在解决方案资源管理器中右击目标项目，然后依次单击
    ///     “添加引用”->“项目”->[浏览查找并选择此项目]
    ///
    ///
    /// 步骤 2)
    /// 继续操作并在 XAML 文件中使用控件。
    ///
    ///     <MyNamespace:CalendarDayControl/>
    ///
    /// </summary>
    [TemplatePart(Name = CalendarDayControl.ElementCalendarDayTextBox, Type = typeof(TextBlock))]
    [TemplatePart(Name = CalendarDayControl.ElementCalendarDayTextBoxYL, Type = typeof(TextBlock))]
    [TemplatePart(Name = CalendarDayControl.ElementCalendarDayTextBox11, Type = typeof(TextBlock))]
    [TemplatePart(Name = CalendarDayControl.ElementCalendarDayTextBox12, Type = typeof(TextBlock))]
    [TemplatePart(Name = CalendarDayControl.ElementCalendarDayTextBox13, Type = typeof(TextBlock))]
    [TemplatePart(Name = CalendarDayControl.ElementCalendarDayTextBox3, Type = typeof(TextBlock))]

    public class CalendarDayControl : Control
    {       
        private const string ElementCalendarDayTextBox11 = "PART_CalendarDayTextBox11";
        private const string ElementCalendarDayTextBox12 = "PART_CalendarDayTextBox12";
        private const string ElementCalendarDayTextBox13 = "PART_CalendarDayTextBox13";
   
        private const string ElementCalendarDayTextBoxYL = "PART_CalendarDayTextBoxYL";

        private const string ElementCalendarDayTextBox = "PART_CalendarDayTextBox";

        private const string ElementCalendarDayTextBox3 = "PART_CalendarDayTextBox3";


        TextBlock calendarDayTB = null;
        TextBlock calendarDayTB3 = null;
        TextBlock calendarDayTBYL = null;

        TextBlock calendarDay11TB = null;
        TextBlock calendarDay12TB = null;
        TextBlock calendarDay13TB = null;

        public CalendarDayControl()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(CalendarDayControl), new FrameworkPropertyMetadata(typeof(CalendarDayControl)));
            CalendarDayStr = "1";
        }

        //static CalendarDayControl()
        //{
        //    DefaultStyleKeyProperty.OverrideMetadata(typeof(CalendarDayControl), new FrameworkPropertyMetadata(typeof(CalendarDayControl)));
        //}
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            calendarDayTBYL = GetTemplateChild(ElementCalendarDayTextBoxYL) as TextBlock;

            calendarDayTB = GetTemplateChild(ElementCalendarDayTextBox) as TextBlock;
            calendarDayTB3 = GetTemplateChild(ElementCalendarDayTextBox3) as TextBlock;

            calendarDay11TB = GetTemplateChild(ElementCalendarDayTextBox11) as TextBlock;
            calendarDay12TB = GetTemplateChild(ElementCalendarDayTextBox12) as TextBlock;
            calendarDay13TB = GetTemplateChild(ElementCalendarDayTextBox13) as TextBlock;

        }
        /// <summary>
        /// Registers a dependency property as backing store for the Content property
        /// </summary>
        public static readonly DependencyProperty CalendarDayStrProperty =
            DependencyProperty.Register("CalendarDayStr", typeof(object), typeof(CalendarDayControl),
                new FrameworkPropertyMetadata(null,
                    FrameworkPropertyMetadataOptions.AffectsRender |
                    FrameworkPropertyMetadataOptions.AffectsParentMeasure));

        /// <summary>
        /// Gets or sets the Content.
        /// </summary>
        /// <value>The Content.</value>
        public object CalendarDayStr
        {
            get { return (object)GetValue(CalendarDayStrProperty); }
            set { SetValue(CalendarDayStrProperty, value); }
        }

        /// <summary>
        /// Registers a dependency property as backing store for the Content property
        /// </summary>
        public static readonly DependencyProperty CalendarDayStrYLProperty =
            DependencyProperty.Register("CalendarDayStrYL", typeof(object), typeof(CalendarDayControl),
                new FrameworkPropertyMetadata(null,
                    FrameworkPropertyMetadataOptions.AffectsRender |
                    FrameworkPropertyMetadataOptions.AffectsParentMeasure));

        /// <summary>
        /// Gets or sets the Content.
        /// </summary>
        /// <value>The Content.</value>
        public object CalendarDayStrYL
        {
            get { return (object)GetValue(CalendarDayStrYLProperty); }
            set { SetValue(CalendarDayStrYLProperty, value); }
        }

        #region CalendarDayStr11
        /// <summary>
        /// Registers a dependency property as backing store for the CalendarDayStr11 property
        /// </summary>
        public static readonly DependencyProperty CalendarDayStr11Property =
            DependencyProperty.Register("CalendarDayStr11", typeof(object), typeof(CalendarDayControl),
                new FrameworkPropertyMetadata(null,
                    FrameworkPropertyMetadataOptions.AffectsRender |
                    FrameworkPropertyMetadataOptions.AffectsParentMeasure));

        /// <summary>
        /// Gets or sets the CalendarDayStr11.
        /// </summary>
        /// <value>The CalendarDayStr11.</value>
        public object CalendarDayStr11
        {
            get { return (object)GetValue(CalendarDayStr11Property); }
            set { SetValue(CalendarDayStr11Property, value); }
        }
        #endregion
        #region CalendarDayStr12
        /// <summary>
        /// Registers a dependency property as backing store for the CalendarDayStr12 property
        /// </summary>
        public static readonly DependencyProperty CalendarDayStr12Property =
            DependencyProperty.Register("CalendarDayStr12", typeof(object), typeof(CalendarDayControl),
                new FrameworkPropertyMetadata(null,
                    FrameworkPropertyMetadataOptions.AffectsRender |
                    FrameworkPropertyMetadataOptions.AffectsParentMeasure));

        /// <summary>
        /// Gets or sets the CalendarDayStr12.
        /// </summary>
        /// <value>The CalendarDayStr12.</value>
        public object CalendarDayStr12
        {
            get { return (object)GetValue(CalendarDayStr12Property); }
            set { SetValue(CalendarDayStr12Property, value); }
        }
        #endregion
        #region CalendarDayStr13
        /// <summary>
        /// Registers a dependency property as backing store for the CalendarDayStr13 property
        /// </summary>
        public static readonly DependencyProperty CalendarDayStr13Property =
            DependencyProperty.Register("CalendarDayStr13", typeof(object), typeof(CalendarDayControl),
                new FrameworkPropertyMetadata(null,
                    FrameworkPropertyMetadataOptions.AffectsRender |
                    FrameworkPropertyMetadataOptions.AffectsParentMeasure));

        /// <summary>
        /// Gets or sets the CalendarDayStr13.
        /// </summary>
        /// <value>The CalendarDayStr13.</value>
        public object CalendarDayStr13
        {
            get { return (object)GetValue(CalendarDayStr13Property); }
            set { SetValue(CalendarDayStr13Property, value); }
        }
        #endregion
        #region CalendarDayStr3
        /// <summary>
        /// Registers a dependency property as backing store for the CalendarDayStr13 property
        /// </summary>
        public static readonly DependencyProperty CalendarDayStr3Property =
            DependencyProperty.Register("CalendarDayStr3", typeof(object), typeof(CalendarDayControl),
                new FrameworkPropertyMetadata(null,
                    FrameworkPropertyMetadataOptions.AffectsRender |
                    FrameworkPropertyMetadataOptions.AffectsParentMeasure));

        /// <summary>
        /// Gets or sets the CalendarDayStr13.
        /// </summary>
        /// <value>The CalendarDayStr13.</value>
        public object CalendarDayStr3
        {
            get { return (object)GetValue(CalendarDayStr3Property); }
            set { SetValue(CalendarDayStr3Property, value); }
        }
        #endregion

    }
}
